{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eb92b0dd-3c28-4ff5-b636-9c204c446005",
   "metadata": {},
   "source": [
    "# Bitwise Invert\n",
    "\n",
    "The bitwise inversion operation receives a quantum register representing some number $x$,\n",
    "and inverts its binary representation, namely, replaces $1$s by $0$s and vice versa."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5eba81d0-4776-43cc-b503-3b2bba07c24f",
   "metadata": {},
   "source": [
    "# Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4fd85f09-fb85-4f00-8938-be3854c6c49c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:21:56.380344Z",
     "iopub.status.busy": "2024-05-07T13:21:56.379740Z",
     "iopub.status.idle": "2024-05-07T13:21:59.339921Z",
     "shell.execute_reply": "2024-05-07T13:21:59.339105Z"
    }
   },
   "outputs": [],
   "source": [
    "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
    "\n",
    "\n",
    "@qfunc\n",
    "def main(x: Output[QNum], y: Output[QNum]) -> None:\n",
    "    prepare_int(6, x)\n",
    "\n",
    "    y |= ~x\n",
    "\n",
    "\n",
    "qmod = create_model(main)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "002c8028-c157-468a-8c2e-cefa10c4c0d4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:21:59.344820Z",
     "iopub.status.busy": "2024-05-07T13:21:59.343558Z",
     "iopub.status.idle": "2024-05-07T13:22:02.073544Z",
     "shell.execute_reply": "2024-05-07T13:22:02.072665Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{('011', '100'): 1000}\n"
     ]
    }
   ],
   "source": [
    "from classiq import execute, synthesize, write_qmod\n",
    "\n",
    "write_qmod(qmod, \"bitwise_invert_example\")\n",
    "qprog = synthesize(qmod)\n",
    "\n",
    "result = execute(qprog).result()[0].value\n",
    "print(result.counts_of_multiple_outputs([\"x\", \"y\"]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
